'''
Created on 22/04/2012

@author: joan
'''
import Queue

MAX_INT = 1000
class Candidates(object):
    '''
    classdocs
    '''


    def __init__(self,maxsize=40):
        '''
        Constructor
        '''
        '''
        Each element is a list of
        [sortScore, score, word, 
        '''
    
        self.Q = Queue.PriorityQueue(maxsize);
        self.minElem = MAX_INT
        
    def add(self,elem):

        
        if self.Q.full():
            if elem < self.minElem:
                return
             
            self.Q.get()
        
        if elem < self.minElem:
            self.minElem = elem      
        
        self.Q.put(elem,False)
              
        
    def __str__(self):
        str_out = ""
        for i in range(self.Q.qsize()):

            str_out += "%d. %d->"%(i,self.Q.get(i))
        return str_out
    
    def tolist(self):
        n = self.Q.qsize();
        l = [[] for i in range(n)]
        
        
        while not self.Q.empty():
            n -= 1;
            l[n] = (self.Q.get())
            
        return l
if __name__ == '__main__':
    
    
    PQ = Candidates(3)
            
    PQ.add(1)
    PQ.add(2)
    PQ.add(3)
    PQ.add(4)
    print PQ.tolist()
    